import evaluationPopup from "../../home/components/evaluation_popup"
import { scrollMixin } from '../../../../../utils/mixin';
export default {
  mixins: [scrollMixin],
  data() {
    return {
      active_name: 'all',
      order_type: 1,
      evaluation_show: false,
      point: {},
      urlStr:"",
      order_id:"",

      list: [],
      isLoadMore: true,
      page: 1,
      total_page: 0,
    };
  },
  activated() {
    this.evaluation_show = false;
    this.isLoadMore = true;
    if (localStorage.getItem('myLocation')) {
      let myLocation = JSON.parse(localStorage.getItem('myLocation'));
      this.point = myLocation.point;
      this.getData();
    } else {
      this.ready()
    }
  },
  methods: {
    goToAdress(item){
      // let point = this.fun.bd_decrypt(item.longitude,item.latitude);
      let point =  { lng: item.longitude * 1, lat: item.latitude * 1 };
      this.fun.goToWXAdress(point, item.order_address.address, '');
    },
    ready() {
      this.fun
        .getLocation()
        .then(res => {
          console.log(res, "res");
          this.point = res.point;
          this.getData();
        })
        .catch(err => {
          console.log(err);
        });
    },
    change() {
      this.getData();
    },
    getMoreData() {
      this.isLoadMore = false
      if (this.page >= this.total_page) {
        return;
      }
      let page = this.page + 1;
      this.getData(page);
    },
    getData(page = 1) {
      let json = { page ,lng:this.point.lng,lat:this.point.lat};
      if (this.activeName !== 'all') {
        json.tab = this.activeName;
      }
      $http.get('plugin.be-within-call.frontend.order.shi-fu.index', json, "").then(res => {
        this.isLoadMore = true;
        if (res.result) {
          let data = res.data;
          this.page = data.current_page;
          this.total_page = data.last_page;
          (page == 1) ? (this.list = data.data) : (this.list = this.list.concat(data.data))
        } else {
          this.$toast(res.msg);
        }
      })
    },
    optionType(type) {
      this.order_type = type;
    },
    commentEvent(){
      this.getData();
    },
    order_handle(item,order_id) {
      if(item.value == 'shifu'){
        this.urlStr = item.api;
        this.order_id = order_id;
        this.evaluation_show = true;
      }
      if (item.value == 'receive') {
        $http.post('plugin.be-within-call.frontend.need-order-operate.receive', { oid: order_id }).then(res => {
          this.$toast(res.msg);
          if (res.result) {
            this.getData();
          }
        })
      }
    },
    // 跳转订单详情
    goOrderDetail({ order_id, status,button_models }) {
      let order_type = "";
      if (status == 3) {
        if(button_models && button_models.length!==0){
          order_type = 1;
        }else{
          order_type = 5
        }
      } else if (status == 2) {
        order_type = 2;
      } else if(status == 0){
        order_type = 4
      }else if(status==-1){
        order_type=-1;
      }
      this.$router.push(
        this.fun.getUrl("anytimeSkillMasterOrderDetail", { order_id, order_type, name: 'individual' })
      );
    }
  },
  components: { evaluationPopup }
};
